package com.example.beautymakeup.service.impl;

import com.example.beautymakeup.dao.CommentDao;
import com.example.beautymakeup.dao.OrderDao;
import com.example.beautymakeup.dao.ShopDao;
import com.example.beautymakeup.pojo.Comment;
import com.example.beautymakeup.pojo.Order;
import com.example.beautymakeup.pojo.Shop;
import com.example.beautymakeup.service.CommentService;
import com.example.beautymakeup.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentDao commentDao;
    @Autowired
    private OrderDao orderDao;

    @Override
    public boolean add(String token, Comment comment) throws Exception {
        String subject = JwtUtil.parseJWT(token).getSubject();
        if (!"admin".equals(subject)){
            comment.setUserId(Integer.valueOf(subject));
            int add = commentDao.add(comment);
            if (add == 1){
              Order order = new Order();
              order.setUid(comment.getOrderId());
              order.setStatus(2);
                int update = orderDao.update(order);
                if (update == 1){
                    return true;
                }
            }
            return  false;
        }
        return false;
    }
}
